package application.view.viewComponent.mainNav 
{
	import application.model.VO.ModuleNavItemVO;
	import flash.display.Sprite;
	import caurina.transitions.Tweener;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import ginger.events.DataEvent;
	/**
	 * ...
	 * @author Ning
	 */
	public class NavList extends Sprite
	{
		private var _hgap:Number;
		private var _data:Array;
		public function set hgap(value:Number):void{
			_hgap = value;
		}

		public function NavList() 
		{

		}
		public function show():void
		{
			for (var i:int = 0; i < this.numChildren; i++ )
			{
				var item:NavListItem = getChildAt(i) as NavListItem;
				Tweener.removeTweens(item);
				item.alpha = 0;
				item.y = 0;
				Tweener.addTween(item, { time:.5, delay:i * .05,alpha:1, y: i * (item.height + _hgap) } );
			}
		}
		public function leave():void
		{
			for (var i:int = 0; i < this.numChildren; i++ )
			{
				var item:NavListItem = getChildAt(i) as NavListItem;
				Tweener.addTween(item, { time:.5, delay:i * .05,alpha:0, y:_data.length * (item.height + _hgap) } );
			}
		}
		public function updateData(data:Array):void
		{
			_data = data;
			for (var i:int = 0; i < data.length; i++ )
			{
				var vo:ModuleNavItemVO = data[i] as ModuleNavItemVO;
				var item:NavListItem = new NavListItem(vo);
				item.addEventListener(MouseEvent.CLICK, onItemClick);
				addChild(item);
				item.y = i * (item.height + _hgap);
			}
		}
		private function onItemClick(evt:MouseEvent):void
		{
			var item:NavListItem = evt.target as NavListItem;
			dispatchEvent(new DataEvent(Event.SELECT, item.moduleName));
		}
	}
}